package thread;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

class DateUtil{
    static SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

    public static synchronized Date parse(String str){

        try {
            return sdf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
            throw new RuntimeException("日期转换异常");
        }

    }

}

public class DateUtilDemo {
    public static void main(String[] args) {

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                   Date date = DateUtil.parse("2020/01/01 01:01:01");
                    System.out.println(date);
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                  Date date=  DateUtil.parse("2020/01/01 01:01:01");
                    System.out.println(date);
                }
            }
        }).start();


    }
}

class DateUtilDemo2{
    public void Util(){
        Date date = new Date();
        System.out.println(date);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        String str = sdf.format(date);
        System.out.println(str);

        try {
            date = sdf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
